package com.crm.system.controller.index;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.recruitmentManagement.AnnouncementQO;
import com.crm.model.vo.announcement.AnnouncementVO;
import com.crm.system.service.index.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wll
 * @date 2020/12/18 14:09
 */
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Autowired
    AnnouncementService announcementService;


    /**
     * @param pageIndex
     * @param pageSize
     * @param searchInfo   搜索条件
     * @param publicStatus 发布状态 0:已发布; 1:已删除',
     * @return
     * @author wll
     * @date 2020/12/21 08:50
     * info 首页-公告列表
     */
    @PostMapping("/pageList")
    public DataResponse getList(@RequestParam(value = "pageIndex") Integer pageIndex,
                                @RequestParam(value = "pageSize") Integer pageSize,
                                @RequestParam(value = "searchInfo", required = false) String searchInfo,
                                @RequestParam(value = "publicStatus", required = false) Integer publicStatus,
                                @RequestParam(value = "sort", required = false) String sort,
                                @RequestParam(value = "sortOrder", required = false) String sortOrder) {
        DhPageInfo<AnnouncementVO> announcements = announcementService.getList(pageIndex, pageSize, searchInfo, publicStatus,sort,sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), announcements);
    }



    /**
     * @param
     * @return
     * @author wll
     * @date 2020/12/21 08:50
     * info 首页-修改公告置顶状态
     */
    @PostMapping("/modifyIstop")
    public DataResponse updateIstop(@RequestParam(value = "id") String id,
                                    @RequestParam(value = "isTop") Integer isTop) {
        Boolean result = announcementService.updateIstop(id, isTop);
        if (result) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }

    }



    /**
     * @param announcementQO
     * @return
     * @author wll
     * @date 2020/12/21 08:50
     * info 首页-发布公告
     */
    @PostMapping("/save")
    public DataResponse add(@RequestBody AnnouncementQO announcementQO) {
        Boolean result = announcementService.add(announcementQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }



    /**
     * @param announcementQO
     * @return
     * @author wll
     * @date 2020/12/21 08:50
     * info 首页-修改公告
     */
    @PostMapping("/modify")
    public DataResponse update(@RequestBody AnnouncementQO announcementQO) {
        Boolean result = announcementService.update(announcementQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }



    /**
     * @param id 通知id
     * @return
     * @author wll
     * @date 2020/12/21 08:50
     * info 首页-删除公告
     */
    @GetMapping("/delete")
    public DataResponse delete(@RequestParam(value = "id") String id) {
        Boolean result = announcementService.delete(id);
        if (result) {
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        } else {
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }





}
